package com.carrent.bus.controller;

import com.carrent.bus.service.CustomerService;
import com.carrent.bus.vo.CustomerVo;
import com.carrent.sys.utils.DataGridView;
import com.carrent.sys.utils.ResultObj;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 客户管理控制器
 *
 */
@RestController
@Api(tags = "客户管理控制器")
@RequestMapping(value = "customer")
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    /**
     * 查询所有客户
     * @param customerVo
     * @return DataGridView
     */
    @RequestMapping("loadAllCustomer")
    public DataGridView loadAllCustomer(CustomerVo customerVo){
        DataGridView dataGridView= customerService.loadAllCustomer(customerVo);
        return dataGridView;
    }

    /**
     * 添加客户
     * @param customerVo
     * @return ResultObj
     */
    @RequestMapping("addCustomer")
    public ResultObj addCustomer(CustomerVo customerVo){
        try{
            customerService.addCustomer(customerVo);
            return ResultObj.ADD_SUCCESS;
        }catch (Exception e){
            return ResultObj.ADD_ERROR;
        }
    }

    /**
     * 删除客户
     * @param customerVo
     * @return ResultObj
     */
    @RequestMapping("deleteCustomer")
    public ResultObj deleteCustomer(String identity){
        try{
            customerService.deleteCustomer(identity);
            return ResultObj.DELETE_SUCCESS;
        }catch (Exception e){
            return ResultObj.DELETE_ERROR;
        }
    }

    /**
     * 修改
     * @param customerVo
     * @return ResultObj
     */
    @RequestMapping("updateCustomer")
    public ResultObj updateCustomer(CustomerVo customerVo){
        try{
            customerService.updateCustomer(customerVo);
            return ResultObj.UPDATE_SUCCESS;
        }catch (Exception e){
            return ResultObj.UPDATE_ERROR;
        }
    }

    /**
     * 批量删除
     * @param customerVo
     * @return ResultObj
     */
    @RequestMapping("deleteBatchCustomer")
    public ResultObj deleteBatchCustomer(CustomerVo customerVo){
        try {
            customerService.deleteBatchCustomer(customerVo.getIds());
            return ResultObj.DELETE_SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return ResultObj.DELETE_ERROR;
        }
    }

}
